package com.xt.LibaryDeskManager.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xt.LibaryDeskManager.dao.StudentMapper;
import com.xt.LibaryDeskManager.dto.StudentDto;
import com.xt.LibaryDeskManager.dto.UserMessage;
import com.xt.LibaryDeskManager.service.StudentService;
import com.xt.LibaryDeskManager.utils.StrUtils;
import com.xt.LibaryDeskManager.vo.LoginVo;
import com.xt.LibaryDeskManager.vo.StudentVo;
import com.xt.LibaryDeskManager.vo.UpdateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author 童归权
 * @version 1.0 2021/1/31
 */
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
   private StudentMapper studentMapper;
    @Override
    public UserMessage selectByLoginVo(LoginVo loginVo) throws Exception {
        return studentMapper.selectByLoginVo(loginVo);
    }

    @Override
    public int updateStudent(UpdateVo updateVo) throws Exception {
        return studentMapper.updateStudent(updateVo);
    }

    @Override
    public UserMessage selectByNo(String id) throws Exception {
        return studentMapper.selectByNo(id);
    }

    @Override
    public int addStudent(StudentVo studentVo) throws Exception {
        return studentMapper.addStudent(studentVo);
    }

    @Override
    public List<UserMessage> selectAll() throws Exception {
        return studentMapper.selectAll1();
    }

    @Override
    public Map selectAll(Integer page, Integer limit,StudentVo studentVo) throws Exception {
        Page page1=PageHelper.startPage(page,limit,true);
        List<StudentDto> list= studentMapper.selectAll(studentVo);
        return StrUtils.creatMap(list,page1.getTotal());
    }

    @Override
    public int updateValid(String studentNo, Boolean valid) throws Exception {
        return studentMapper.updateValid(studentNo,valid);
    }

    @Override
    public int updateStudent(StudentVo studentVo) throws Exception {
        return studentMapper.updateStudent1(studentVo);
    }

    @Override
    public int deleteStudent(String id) throws Exception {

        return studentMapper.deleteStudent(id);
    }

    @Override
    public int getCount() throws Exception {
        return studentMapper.getCount();
    }
}
